<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <script>
    window.onload=function (){
      let oBtn=document.getElementById('btn1');
      let oSvg=document.getElementById('svg1');

      oBtn.onclick=function (){
        //let oL=document.createElement('line');
        let oL=document.createElementNS('http://www.w3.org/2000/svg', 'line');

        //alert(oL);
        //alert(oSvg.children[0]);

        oL.setAttribute('x1', 100);
        oL.setAttribute('y1', 100);
        oL.setAttribute('x2', 400);
        oL.setAttribute('y2', 300);

        oL.style.stroke='red';

        oSvg.appendChild(oL);
      };
    };
    </script>
  </head>
  <body>
    <input type="button" id="btn1" name="" value="按钮"><br>
    <svg id="svg1" width="800" height="600">
      <line x1="150" y1="100" x2="450" y2="300" style="stroke: yellow;"></line>
    </svg>
  </body>
</html>
